<?php
session_start();
require('fpdf.php');
mysql_connect('localhost','root','');
mysql_select_db('techworks');

if (isset($_SESSION['plan_id'])){
$plan_id = $_SESSION['plan_id'];
}
if (isset($_GET['id'])){
$plan_id = $_GET['id'];	
}

// cover-page
$qry = mysql_query("SELECT * FROM tw_cover_page WHERE plan_id = $plan_id");
if(!$qry){
	echo mysql_error();
	exit();
}
$row = mysql_fetch_array($qry);


$comp_name = $row['comp_name'];
$owner = $row['own_name'];
$address = $row['address'];
$city = $row['city'];
$zip = $row['zip'];
$state = $row['state'];
$phone = $row['phone'];
$fax = $row['fax'];
$mail = $row['email'];
$logo = $row['logo'];
$user = $row['user_id'];



// executive-summery
$qry = mysql_query("SELECT * FROM tw_executive_summery WHERE plan_id = $plan_id");
if(!$qry){
	echo mysql_error();
	exit();
}
$row = mysql_fetch_array($qry);

$business_services = $row['business-services'];
$target_customer = $row['target-customers'];
$company_goals = $row['company-goals'];


// company-description
$qry = mysql_query("SELECT * FROM tw_company_desc WHERE plan_id = $plan_id");
if(!$qry){
	echo mysql_error();
	exit();
}
$row = mysql_fetch_array($qry);

$mission_statement = $row['mission-statement'];
$principal_members = $row['principal-members'];
$legal_structure = $row['legal-structure'];

// market-research
$qry = mysql_query("SELECT * FROM tw_market_research WHERE plan_id = $plan_id");
if(!$qry){
	echo mysql_error();
	exit();
}
$row = mysql_fetch_array($qry);

$desc_industry = $row['desc_industry'];
$desc_customers = $row['desc_customers'];
$industry_competitors = $row['industry_competitors'];
$competition_adv = $row['competition_adv'];
$company_regulation = $row['company_regulation'];

// Product/Service-Line
$qry = mysql_query("SELECT * FROM tw_services_line WHERE plan_id = $plan_id");
if(!$qry){
	echo mysql_error();
	exit();
}
$row = mysql_fetch_array($qry);

$products_services = $row['products_services'];
$pricing_structure = $row['pricing_structure'];
$life_cycle = $row['life_cycle'];
$intelectual_right = $row['intelectual_right'];
$research_dev = $row['research_dev'];

// Marketing
$qry = mysql_query("SELECT * FROM tw_com_plans WHERE plan_id = $plan_id");
if(!$qry){
	echo mysql_error();
	exit();
}
$row = mysql_fetch_array($qry);

$overall_plan = $row['overall-plan'];
$communicate_with_cus = $row['communicate-with-cus'];
$selling_products = $row['selling-products'];

session_destroy();

// CLASS WILL START HERE
class PDF extends FPDF
{
	// Mustafa: In this class we will not put Header and Footer methods, because it will appear in all pages.
	// Mustafa: Cover page. This page doesn't have Header and Footer
	function CoverPage()
	{
		global $comp_name, $owner, $address, $city, $zip, $state, $phone, $fax, $mail, $logo, $user_id;
		// Logo
		$this->Image('logo.png',35,55,15,15);
		// Arial bold 15
		$this->SetFont('Helvetica','B',40);
		// Move to the right
		$this->Cell(40);
		// Title
		$this->SetXY(50,50);
		$this->SetTextColor(50,60,70);
		$this->Cell(80,30,$comp_name,0,0,'C');

		// Line break
		$this->Ln(20);

		$this->SetX(52);
		$this->SetFont('Helvetica','',12);
		$this->Write(5, $mail);

		$this->Ln(50);
		$this->SetX(30);
		$this->SetFont('Helvetica','',12);
		$this->Write(30, 'Owner: ');
		$this->Write(30, $owner);

		$this->Ln(10);
		$this->SetX(30);
		$this->SetFont('Helvetica','',12);
		$this->Write(30, 'Address: ');
		$this->Write(30, $address);

		$this->Ln(10);
		$this->SetX(30);
		$this->SetFont('Helvetica','',12);
		$this->Write(30, 'City: ');
		$this->Write(30, $city);

		$this->Ln(10);
		$this->SetX(30);
		$this->SetFont('Helvetica','',12);
		$this->Write(30, 'Zip: ');
		$this->Write(30, $zip);

		$this->Ln(10);
		$this->SetX(30);
		$this->SetFont('Helvetica','',12);
		$this->Write(30, 'State: ');
		$this->Write(30, $state);

		$this->Ln(10);
		$this->SetX(30);
		$this->SetFont('Helvetica','',12);
		$this->Write(30, 'Phone: : ');
		$this->Write(30, $phone);

		$this->Ln(10);
		$this->SetX(30);
		$this->SetFont('Helvetica','',12);
		$this->Write(30, 'Fax: ');
		$this->Write(30, $fax);

		$this->Ln(10);
		$this->SetX(30);
		$this->SetFont('Helvetica','',12);
		$this->Write(30, 'Email: ');
		$this->Write(30, $mail);



	}

	function ExecutiveSummery(){

		global $business_services, $target_customer, $company_goals;

		// HEADER START
		// Logo
		$this->Image('logo.png',10,6,30);
		// Arial bold 15
		$this->SetFont('Arial','B',18);
		// Move to the right
		$this->Cell(80);
		// Title
		$this->SetXY(80, 40);
		$this->Cell(30,10,'1. Executive Summery',0,0,'C');
		// Line break
		$this->Ln(20);


		//PAGE CONTENT 
		$this->SetX(25);
		$this->SetFont('Helvetica','B',12);
		$this->Write(5, '1.1   Products or services that this business provides: ');
		$this->Ln(5);
		$this->SetX(35);
		$this->SetFont('Helvetica','',12);
		$this->Write(6, $business_services);
		$this->Ln(20);

		$this->SetX(25);
		$this->SetFont('Helvetica','B',12);
		$this->Write(5, '1.2   Target customers of this business: ');
		$this->Ln(5);
		$this->SetX(35);
		$this->SetFont('Helvetica','',12);
		$this->Write(6, $target_customer);
		$this->Ln(20);

		$this->SetX(25);
		$this->SetFont('Helvetica','B',12);
		$this->Write(5, '1.3   The company main goals: ');
		$this->Ln(5);
		$this->SetX(35);
		$this->SetFont('Helvetica','',12);
		$this->Write(6, $company_goals);
		$this->Ln(20);


		// FOOTER START
		// Position at 1.5 cm from bottom
		$this->Ln(30);
		$this->SetY(266);
		// Arial italic 8
		$this->SetFont('Arial','I',8);
		// Page number
		$this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');

	}


	function CompanyDescription(){

		global $mission_statement, $principal_members, $legal_structure;

		// HEADER START
		// Logo
		$this->Image('logo.png',10,6,30);
		// Arial bold 15
		$this->SetFont('Arial','B',18);
		// Move to the right
		$this->Cell(80);
		// Title
		$this->SetXY(80, 40);
		$this->Cell(30,10,'2. Company Description',0,0,'C');
		// Line break
		$this->Ln(20);
		

		// PAGE CONTENT 
		$this->SetX(25);
		$this->SetFont('Helvetica','B',12);
		$this->Write(5, '2.1   Mission Statement: ');
		$this->Ln(5);
		$this->SetX(35);
		$this->SetFont('Helvetica','',12);
		$this->Write(6, $mission_statement);
		$this->Ln(20);

		$this->SetX(25);
		$this->SetFont('Helvetica','B',12);
		$this->Write(5, '2.2   Principle members of the company and thier roles: ');
		$this->Ln(5);
		$this->SetX(35);
		$this->SetFont('Helvetica','',12);
		$this->Write(6, $principal_members);
		$this->Ln(20);

		$this->SetX(25);
		$this->SetFont('Helvetica','B',12);
		$this->Write(5, '2.3   Legal Structure of the company: ');
		$this->Ln(5);
		$this->SetX(35);
		$this->SetFont('Helvetica','',12);
		$this->Write(6, $legal_structure);
		$this->Ln(20);


		// FOOTER START
		// Position at 1.5 cm from bottom
		$this->Ln(30);
		$this->SetY(266);
		// Arial italic 8
		$this->SetFont('Arial','I',8);
		// Page number
		$this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');

	}

	function MarketResearch(){

		global $desc_industry, $desc_customers, $industry_competitors, $competition_adv, $company_regulation;

		// HEADER START
		// Logo
		$this->Image('logo.png',10,6,30);
		// Arial bold 15
		$this->SetFont('Arial','B',18);
		// Move to the right
		$this->Cell(80);
		// Title
		$this->SetXY(80, 40);
		$this->Cell(30,10,'3. Market Research',0,0,'C');
		// Line break
		$this->Ln(20);


		// PAGE CONTENT 
		$this->SetX(25);
		$this->SetFont('Helvetica','B',12);
		$this->Write(5, '3.1   Describe the industry: ');
		$this->Ln(5);
		$this->SetX(35);
		$this->SetFont('Helvetica','',12);
		$this->Write(6, $desc_industry);
		$this->Ln(20);

		$this->SetX(25);
		$this->SetFont('Helvetica','B',12);
		$this->Write(5, '3.2   Describe customers: ');
		$this->Ln(5);
		$this->SetX(35);
		$this->SetFont('Helvetica','',12);
		$this->Write(6, $desc_customers);
		$this->Ln(20);

		$this->SetX(25);
		$this->SetFont('Helvetica','B',12);
		$this->Write(5, '3.3   Industry Competitors: ');
		$this->Ln(5);
		$this->SetX(35);
		$this->SetFont('Helvetica','',12);
		$this->Write(6, $industry_competitors);
		$this->Ln(20);

		$this->SetX(25);
		$this->SetFont('Helvetica','B',12);
		$this->Write(5, '3.4   Competition Advantages: ');
		$this->Ln(5);
		$this->SetX(35);
		$this->SetFont('Helvetica','',12);
		$this->Write(6, $competition_adv);
		$this->Ln(20);

		$this->SetX(25);
		$this->SetFont('Helvetica','B',12);
		$this->Write(5, '3.5   Regulations that are applied on the company: ');
		$this->Ln(5);
		$this->SetX(35);
		$this->SetFont('Helvetica','',12);
		$this->Write(6, $company_regulation);
		$this->Ln(20);


		// FOOTER START
		// Position at 1.5 cm from bottom
		$this->Ln(30);
		$this->SetY(266);
		// Arial italic 8
		$this->SetFont('Arial','I',8);
		// Page number
		$this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');

	}
	
function ProductServiceLine(){

		global $products_services, $pricing_structure, $life_cycle, $intelectual_right, $research_dev;

		// HEADER START
		// Logo
		$this->Image('logo.png',10,6,30);
		// Arial bold 15
		$this->SetFont('Arial','B',18);
		// Move to the right
		$this->Cell(80);
		// Title
		$this->SetXY(80, 40);
		$this->Cell(30,10,'4. Product or Service Line',0,0,'C');
		// Line break
		$this->Ln(20);


		// PAGE CONTENT 
		$this->SetX(25);
		$this->SetFont('Helvetica','B',12);
		$this->Write(5, '4.1   Product or service that the company provides: ');
		$this->Ln(5);
		$this->SetX(35);
		$this->SetFont('Helvetica','',12);
		$this->Write(6, $products_services);
		$this->Ln(20);

		$this->SetX(25);
		$this->SetFont('Helvetica','B',12);
		$this->Write(5, '4.2   Pricing Structure: ');
		$this->Ln(5);
		$this->SetX(35);
		$this->SetFont('Helvetica','',12);
		$this->Write(6, $pricing_structure);
		$this->Ln(20);

		$this->SetX(25);
		$this->SetFont('Helvetica','B',12);
		$this->Write(5, '4.3   Life cycle stage of product or service?: ');
		$this->Ln(5);
		$this->SetX(35);
		$this->SetFont('Helvetica','',12);
		$this->Write(6, $life_cycle);
		$this->Ln(20);

		$this->SetX(25);
		$this->SetFont('Helvetica','B',12);
		$this->Write(5, '4.4   Intellectual property rights for company product or service: ');
		$this->Ln(5);
		$this->SetX(35);
		$this->SetFont('Helvetica','',12);
		$this->Write(6, $intelectual_right);
		$this->Ln(20);

		$this->SetX(25);
		$this->SetFont('Helvetica','B',12);
		$this->Write(5, '3.5   Research and development (R&D) activities for performing or planning: ');
		$this->Ln(5);
		$this->SetX(35);
		$this->SetFont('Helvetica','',12);
		$this->Write(6, $research_dev);
		$this->Ln(20);


		// FOOTER START
		// Position at 1.5 cm from bottom
		$this->Ln(30);
		$this->SetY(266);
		// Arial italic 8
		$this->SetFont('Arial','I',8);
		// Page number
		$this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');

	}
	
function Marketing(){ 

		global $overall_plan, $communicate_with_cus, $selling_products;

		// HEADER START
		// Logo
		$this->Image('logo.png',10,6,30);
		// Arial bold 15
		$this->SetFont('Arial','B',18);
		// Move to the right
		$this->Cell(80);
		// Title
		$this->SetXY(80, 40);
		$this->Cell(30,10,'5. Marketing',0,0,'C');
		// Line break
		$this->Ln(20);


		// PAGE CONTENT 
		$this->SetX(25);
		$this->SetFont('Helvetica','B',12);
		$this->Write(5, '4.1   Overall plan to grow the company: ');
		$this->Ln(5);
		$this->SetX(35);
		$this->SetFont('Helvetica','',12);
		$this->Write(6, $overall_plan);
		$this->Ln(20);

		$this->SetX(25);
		$this->SetFont('Helvetica','B',12);
		$this->Write(5, '4.2   Communication with customers: ');
		$this->Ln(5);
		$this->SetX(35);
		$this->SetFont('Helvetica','',12);
		$this->Write(6, $communicate_with_cus);
		$this->Ln(20);

		$this->SetX(25);
		$this->SetFont('Helvetica','B',12);
		$this->Write(5, '4.3   The selling way: ');
		$this->Ln(5);
		$this->SetX(35);
		$this->SetFont('Helvetica','',12);
		$this->Write(6, $selling_products);
		$this->Ln(20);



		// FOOTER START
		// Position at 1.5 cm from bottom
		$this->Ln(30);
		$this->SetY(266);
		// Arial italic 8
		$this->SetFont('Arial','I',8);
		// Page number
		$this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');

	}
}

// Instanciation of inherited class
$pdf = new PDF();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('Times','',12);

// Call pages after this:
// Call Cover Page
$pdf->CoverPage();

// add a page to move to the next page every time
$pdf->AddPage();
// now call the second page
$pdf->ExecutiveSummery();

$pdf->AddPage();
$pdf->CompanyDescription();

$pdf->AddPage();
$pdf->MarketResearch();

$pdf->AddPage();
$pdf->ProductServiceLine();

$pdf->AddPage();
$pdf->Marketing();




// AFTER ALL THINGS, Call the OutPut() method.
$pdf->Output();
?>